package JarJunit;
import java.beans.XMLEncoder;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.*;

import sun.java2d.windows.GDIRenderer.Tracer;

import Common.TraceWriter;


public class UsageExampleMain {
	
	static final String jar_path = "d:\\temp\\cloud\\jars\\complextest.jar";
	
	
	public static void main(String[] args) throws Exception
	{
		List<String> classes_list = new ArrayList<String>();
		
		int total_num_of_tests_in_jar = JarJunitTestsParser.get_test_classes_from_jar(jar_path, classes_list);
		TraceWriter.trace("main: total num of tests in jar file is "+total_num_of_tests_in_jar);
		
		for (int j = 0; j < classes_list.size(); j++)
		{
			TraceWriter.trace(classes_list.get(j));
			JarJunitResult result = JarJunitTestRunner.run_tests_from_class_in_jar(jar_path, classes_list.get(j));
			
			try
			{
				FileOutputStream os = new FileOutputStream("D:\\temp\\cloud\\UT_result.xml");
				XMLEncoder encoder = new XMLEncoder(os);
				encoder.writeObject(result);
				encoder.close();
			}
			catch (FileNotFoundException e)
			{
				TraceWriter.trace("no file found");
				e.printStackTrace();
			}
			
		}
		
		TraceWriter.trace("getting test methods!");
		List<String> test_methods = JarJunitTestsParser.get_test_methods_from_jar(jar_path,"testing/testStudent.class");
		for (String method: test_methods)
		{
			TraceWriter.trace("method found: "+method);
		}
	}
}
